package com.thauanLopes.bacterium.GameManages;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;

import com.game.ThauanFramework.MinhasCoisas;
import com.game.ThauanFramework.SaveManager;
import com.game.ThauanFramework.SoundManager;
import com.thauanLopes.smagasmaga.R;

public class ScoreManager {

	private final String TAG = "Score Manager";
	
	private static int highScore;
	private boolean aplauso = false;

	public static final String highScoreKey = "com.thauanlopes.smagasmama.highScore";
	
	private int score = 0;
	
	public int getScore() {
		return score;
	}

	private int x = 10;
	private int y = 10;
	
	private Paint paint;
	
	private float textSize = 20;
	
	private static ScoreManager instance;
	public static ScoreManager getInstance()
	{
		if(instance == null)
		{
			instance = new ScoreManager();
		}
		
		return instance;
	}
	private ScoreManager()
	{
		this.paint = new Paint();
		paint.setTextSize(textSize);
		paint.setTypeface(MinhasCoisas.getGameTypeface());
	}
	public void Update(double deltaTime)
	{
		
	}
	public void Draw(Canvas canvas)
	{
		canvas.drawText(String.valueOf(score), x, 30, paint);
	}
	
	public void AddScore(int sum)
	{
		this.score += sum;
		Log.i(TAG, String.valueOf(this.score));
		if(this.score > highScore && !this.aplauso)
		{
			SoundManager.getInstance().playSound(R.raw.aplausos_001);
			this.aplauso = true;
		}
	}
	
	public static void Setup()
	{
		highScore = SaveManager.getInstance().LoadInt(highScoreKey);
	}

	// --------------------------- Getters and Setter
	
	public static int getHighScore() {
		return highScore;
	}
	public static void setHighScore(int newhighScore) {
		highScore = newhighScore;
		SaveManager.getInstance().SaveInt(highScoreKey, highScore);
	}
	
	public void Reset()
	{
		this.score = 0;
	}
}
